import pandas as pd
import os
import time
from os import path

time = {}
time1 = {}

def main():
    paths = path.dirname(__file__)
    for root,dirs,files in os.walk(paths):
        for file in files:
            if file != '1.xlsx':
                print('file::',file)
                t1 = os.stat(file).st_mtime
                time[file] = t1
    for k,v in time.items():
        if ('.xlsx' in k) or ('.xls' in k):
            time1[k] = v
    keys = []
    vlues = []
    for k,v in time1.items():
        keys.append(k)
        vlues.append(v)
    x = keys[vlues.index(max(vlues))]
    print('拷贝的最新原文件名为', x)
    save(x)

def save(x):

    news = pd.read_excel(x) #读取待更新的数据文件
    one = pd.read_excel('1.xlsx').fillna('')   #读取目标文件
    one[:max(news.index)+1] = news[:max(news.index)+1]
    one.to_excel('1.xlsx', index=None)
    print('~' * 50)

if __name__ == '__main__':
    news = pd.read_excel(('D:\\xls\\a.xls') #读取待更新的数据文件
    #print(news)
    one = pd.read_excel('D:\\xls\\1.xls',skiprows=1).fillna('')
    #print(one)
   # one[:max(news.index)+1] = news[:max(news.index)+1]
    #one.to_excel('1.xlsx', index=None)
    dataFrame = pd.read_excel('D:\\xls\\a.xls',userows=(2,3,4),skiprows=1)
    print(dataFrame)
    dataFrame.to_excel("1.xlsx", sheet_name='Sheet1', startrow=int(2), index=False)
        # news = pd.read_excel('D:\\xls\\a.xls') #读取待更新的数据文件
    # one = pd.read_excel('D:\\xls\\1.xls').fillna('')   #读取目标文件
    # print('newssss::',news[:max(news.index)+1])
    # print('onesss::',one[:max(news.index)+1])
    # one[:max(news.index)+1] = news[:max(news.index)+1]
    # one.to_excel('D:\\xls\\11.xls', index=None)
    # print('~' * 50)